<?php

namespace App\Http\Controllers\admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use DB;

class OrderController extends Controller
{
    //
    public function index(Request $request)
    {
    	//保存搜索条件
    	$where = [];
    	//实例化要操作的表
    	$db = DB::table("order")->where('state','!=','0')->orderBy('state');
    	//判断有没有要搜索gname字段的值
    	if($request->has("gname")){
    		//获得要搜索gname字段的值
    		$gname = $request->input("gname");
    		//添加where模糊查询匹配条件
    		$db->where("gname","like","%{$gname}%");
    		$where["gname"] = $gname;
    	}
    	//分页
    	$list = $db->paginate(10);
    	//加载模板
    	return view("admin.order.order",["list"=>$list,"where"=>$where]);
    }
    public function destroy($id)
    {
    	$row = DB::table("order")->where("id",$id)->delete();
    	if($row>0){
    		return redirect('admin/order/order');
    	}
    }
    public function edit($id)
    {
    	$row = DB::table("order")->where("id",$id)->first();
    	return view("admin.order.edit",["list"=>$row]);
    }
     public function update($id,Request $request)
     {
     	$data = $request->only("state");
     	$row = DB::table("order")->where("id",$id)->update($data);
     	if($row>0){
     		return redirect("admin/order/order");
     	}
     }

}
